
#include <iostream>

using namespace std;

#include "itkImageFileWriter.h"

#include "dsaio.h"


int main ( int argc, char **argv )
{
  // process command line args
  if ( argc != 3 ) 
  {
    cout << "Usage: " << argv[ 0 ] << " inputDSA outputDSA" << endl;
    return -1;
  }
  char *input_file_name = argv[ 1 ];
  char *output_file_name = argv[ 2 ];
  
  cout << "Input file: " << input_file_name << endl;
  int N = dsa_frame_count ( input_file_name );
  cout << "  frame N:  " << N << endl;
  
  cout << "Read frame No. " << N/2 << endl;
  DsaFrame::Pointer frame = dsa_get_frame ( input_file_name, N/2 );
  
  cout << "Write frame No. " << N/2 << "to 'o.bmp'" << endl;
  typedef itk::ImageFileWriter< DsaFrame > Writer;
  Writer::Pointer writer = Writer::New();
  writer->SetInput ( frame );
  writer->SetFileName ( "o.bmp" );
  writer->Update();
  
  cout << "Append frame to " << output_file_name << endl;
  dsa_append_frame ( output_file_name, frame );
  
  return 0;
}
